JavaScript Conditionals
Conditional Statements
நிபந்தனை அறிக்கைகள் வெவ்வேறு நிபந்தனைகளுக்கு வெவ்வேறு செயல்களைச் செய்ய அனுமதிக்கின்றன.
நிபந்தனை அறிக்கைகள் உண்மை அல்லது பொய் நிபந்தனைகளைப் பொறுத்து வெவ்வேறு குறியீட்டை இயக்குகின்றன.
Conditional Statements Include:
if
அடிப்படை நிபந்தனை சோதனை
if...else
மாற்று வழி வழங்குதல்
if...else if...else
பல நிபந்தனைகளை சோதித்தல்
switch
பல விருப்பங்களுக்கான கிளைப்பிரிவு
ternary (? :)
சுருக்கமான if...else
When to use Conditionals
The if Statement
ஒரு குறிப்பிட்ட நிபந்தனை உண்மையாக இருந்தால் இயக்கப்பட வேண்டிய குறியீட்டு தொகுதியைக் குறிப்பிட if பயன்படுத்தவும்.
Syntax
if (condition) {
// code to execute if the condition is true
}
The else Statement
அதே நிபந்தனை பொய்யாக இருந்தால் இயக்கப்பட வேண்டிய குறியீட்டு தொகுதியைக் குறிப்பிட else பயன்படுத்தவும்.
Syntax
if (condition) {
// code to execute if the condition is true
} else {
// code to execute if the condition is false
}
The else if Statement
முதல் நிபந்தனை பொய்யாக இருந்தால் சோதிக்க புதிய நிபந்தனையைக் குறிப்பிட else if பயன்படுத்தவும்.
Syntax
if (condition1) {
// code to execute if condition1 is true
} else if (condition2) {
// code to execute if the condition1 is false and condition2 is true
} else {
// code to execute if the condition1 is false and condition2 is false
}
The switch Statement
இயக்கப்பட வேண்டிய பல மாற்று குறியீட்டு தொகுதிகளைக் குறிப்பிட switch பயன்படுத்தவும்.
Syntax
switch(expression) {
case x:
// code block
break;
case y:
// code block
break;
default:
// code block
}
Ternary Operator (? :)
if...else க்கான சுருக்கமான வடிவமாக (? :) (ternary) பயன்படுத்தவும்.
Example
condition ? expression1 : expression2
உதவிக்குறிப்பு:
டெர்னரி ஆபரேட்டர் எளிய if...else நிபந்தனைகளுக்கு சிறந்தது. சிக்கலான தர்க்கத்திற்கு if...else அல்லது switch பயன்படுத்தவும்.